package com.Classroom.al.dao;

import com.Classroom.al.dto.StudentClassroom;
import com.Classroom.al.entities.Classroom;
import com.Classroom.al.entities.Student;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentRepository extends CrudRepository<Student,Long> {

@Override
    List<Student> findAll();
    @Query(nativeQuery = true,value=" SELECT s.name, s.phone_num as phonenum, COUNT(s.student_id) as classroomCount "+
            "FROM student s left join classroom_student cs ON s.student_id = cs.student_id "+
            "GROUP BY s.name, s.phone_num ORDER BY 3 DESC ;")
    List<StudentClassroom> studentClassrooms();

}
